#ifndef ELK_WEB_DELEGATE_H
#define ELK_WEB_DELEGATE_H

#include <QObject>

struct ElkRequestDetails
{
    QString url;
    QString method;
    QString referrerUrl;
    QString requestFlags;
    QString resourceType;
    QString transitionType;
};
Q_DECLARE_METATYPE(ElkRequestDetails)

struct ElkContextMenuDetails
{
    QString contextMenuType;
    QString pageUrl;
    QString frameUrl;
    QString frameCharset;
    QString linkUrl;
    QString contextMenuMediaType;
    QString mediaSourceUrl;
    QString mediaTitleText;
    QString selectionText;
};
Q_DECLARE_METATYPE(ElkContextMenuDetails)

class ElkBrowserClient;
class ElkWebDelegate : public QObject
{
    Q_OBJECT

public:
    explicit ElkWebDelegate(QObject *parent);
    ~ElkWebDelegate();

    bool isNull() const;
    void createAsChild(QWidget *parent);

    void setFocus();
    void clearFocus();

    void resize(const QSize &size);
    void resize(int width, int height);

    void load(const QString &url);
    void stopLoad();

    void reload();
    void reloadIgnoreCache();

signals:
    void gotFocus();
    void takeFocus();

    void urlChanged(const QString &url);
    void titleChanged(const QString &title);
    void fullscreenModeChanged(bool fullscreen);
    void loadingProgressChanged(double progress);

    void statusMessage(const QString &message);
    void consoleMessage(const QString &message);

    void downloadRequested(const QString &url, const QString &fileName);

signals:
    void loadStart(const QString &frame);
    void loadEnd(const QString &frame, int httpStatusCode);

    void pageSourceVisited(const QString &frame, const QString &source);
    void displayTextVisited(const QString &frame, const QString &text);

    void beforeBrowser(const QString &frame, const ElkRequestDetails &details,
                       bool userGesture, bool isRedirect);
    void resourceRequested(const QString &frame, const ElkRequestDetails &details);

    void contextMenuShowDetails(const QString &frame,
                                const ElkContextMenuDetails &details);
    void contextMenuDownloadMedia(const QString &frame,
                                  const ElkContextMenuDetails &details);
    void contextMenuViewPageSource(const QString &frame,
                                   const ElkContextMenuDetails &details);
    void contextMenuViewDisplayText(const QString &frame,
                                    const ElkContextMenuDetails &details);

private:
    struct Deleter {
        static inline void cleanup(ElkBrowserClient *pointer) {Q_UNUSED(pointer)}
    };
    QScopedPointer<ElkBrowserClient, Deleter> handler_;
};

#endif // ELK_WEB_DELEGATE_H
